package com.lujianfei.netease_android_touch.utils

import android.graphics.Rect
import android.view.MotionEvent
import android.view.TouchDelegate
import android.view.View


class TouchDelegateComposite(view: View) : TouchDelegate(Rect(), view) {

    private val mDelegates = ArrayList<TouchDelegate>(8)

    fun addDelegate(delegate: TouchDelegate) {
        mDelegates.add(delegate)
    }

    override fun onTouchEvent(event: MotionEvent): Boolean {
        var res = false
        val x = event.x
        val y = event.y
        for (delegate in mDelegates) {
            event.setLocation(x, y)
            res = delegate.onTouchEvent(event) || res
        }
        return res
    }
}